package com.shujia.flink.source

import org.apache.flink.api.common.RuntimeExecutionMode
import org.apache.flink.streaming.api.scala._

object Demo3SocketSource {
  def main(args: Array[String]): Unit = {
    //创建flink环境
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    env.setRuntimeMode(RuntimeExecutionMode.STREAMING)

    /**
     * 基于socket构建source   --  无界流
     *
     * 无界流只能使用流处理模式，不能使用批处理模式
     *
     */

    val linesDS: DataStream[String] = env.socketTextStream("master", 8888)


    linesDS.flatMap(_.split("<"))
      .map((_, 1))
      .keyBy(_._1)
      .sum(1)
      .print()


    env.execute()

  }

}
